define(['./../initial', './../model/Project', './../controller/report/reportCtrl', './../controller/report/report.projectCtrl', './../service/chartFactory', './../directive/calendar', './../directive/singlePointChart'], function () {
    var app = angular.module('App.home');
    app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
        function ($stateProvider, $urlRouterProvider, $locationProvider) {
            $stateProvider
                .state('report', {
                    url: "/report/{projectTypeCode:[a-zA-Z]+}",
                    resolve: {
                        Project: "Project",
                        //提前获取权限项目
                        allProjects: ['Project', '$stateParams', function (Project, $stateParams) {
                            return Project.getAllCityList($stateParams.projectTypeCode);
                        }],
                        actualCode: ['Project', 'allProjects', '$stateParams', '$state', function (Project, allProjects, $stateParams, $state) {
                            //默认访问监护项目，但是如果用户不权限中不包含任何监护，则跳转到第一个默认的权限项目类型中
                            var s = Project.filterPrjTypes.filter(function (item) {
                                return item.projectCode === $stateParams.projectTypeCode;
                            });
                            if (s.length === 0) {
                                $state.go('report', { projectTypeCode: Project.filterPrjTypes[0].projectCode });
                                return 0
                            }
                            return 0;
                        }]
                    },
                    controller: "reportCtrl",
                    templateUrl: "/partials/report/report"
                }).state('report.project', {
                    url: "/project/{prjId:[0-9]+}",
                    resolve: {
                        Project: "Project",
                        chartFactory: "chartFactory",
                        curPrj: ['Project', '$stateParams', 'allProjects', function (Project, $stateParams, allProjects) {
                            var curPrj = Project.getCurProject($stateParams.prjId, allProjects);
                            return curPrj;
                        }],
                        monitorPoints: ['curPrj', function (curPrj) {
                            return curPrj.getMonitorPoints();
                        }],
                        curStatus: ['curPrj', function (curPrj) {
                            return curPrj
                                .getStatusList()
                                .then(function (statusList) {
                                    var curStatus = statusList[statusList.length - 1];
                                    statusList.reverse().some(function (item) {
                                        if (item.StatusImgs.length > 0) {
                                            curStatus.StatusImgs = item.StatusImgs;
                                            curStatus.StatusImgs[0].Date = curStatus.StatusImgs[0].Date.slice(0, 10);
                                            return true;
                                        } else {
                                            return false;
                                        }
                                    })
                                    return curStatus;
                                });
                        }]
                    },
                    controller: "report.projectCtrl",
                    templateUrl: "/partials/report/report/project"
                });
        }
    ]);
});
